
require("Scripts/Common/Utility")
require("Scripts/Common/Class")
require("Scripts/UISystem/EventDispatcher")

CommonEntity = Class(EventDispatcher)

function CommonEntity:Ctor()
	self._name = nil					-- 名称
	self._show = nil					-- 显示对象
	self._parent = nil					-- 父节点

	self._trans_x = 0					-- x轴平移
	self._trans_y = 0					-- y轴平移
	self._trans_z = 0					-- z轴平移

	self._scale_x = 0					-- x轴缩放
	self._scale_y = 0					-- y轴缩放
	self._scale_z = 0					-- z轴缩放

	self._rotate_x = 0					-- x轴旋转
	self._rotate_y = 0					-- y轴旋转
	self._rotate_z = 0					-- z轴旋转

	self._red = 0				-- 红色分量
	self._green = 0				-- 绿色分量
	self._blue = 0				-- 蓝色分量

	self._alpha = 1				-- alpha分量

	self._visible = true		-- 控件是否可见

	self._disable = false		-- 控件是否禁用
end

function CommonEntity:SetTransX(trans_x)
	self._trans_x = trans_x
	if self._show then self._show:SetTransX(trans_x) end
end
function CommonEntity:GetTransX()
	return self._trans_x
end

function CommonEntity:SetTransY(trans_y)
	self._trans_y = trans_y
	if self._show then self._show:SetTransY(trans_y) end
end
function CommonEntity:GetTransY()
	return self._trans_x
end

function CommonEntity:SetTransZ(trans_z)
	self._trans_z = trans_z
	if self._show then self._show:SetTransZ(trans_z) end
end
function CommonEntity:GetTransZ()
	return self._trans_z
end
function CommonEntity:SetScaleX(scale_x)
	self._scale_x = scale_x
	if self._show then self._show:SetScaleX(scale_x) end
end
function CommonEntity:GetScaleX()
	return self._scale_x
end

function CommonEntity:SetScaleY(scale_y)
	self._scale_y = scale_y
	if self._show then self._show:SetScaleY(scale_y) end
end
function CommonEntity:GetScaleY()
	return self._scale_x
end

function CommonEntity:SetScaleZ(scale_z)
	self._scale_z = scale_z
	if self._show then self._show:SetScaleZ(scale_z) end
end
function CommonEntity:GetScaleZ()
	return self._scale_z
end

function CommonEntity:SetRotateX(rotate_x)
	self._rotate_x = rotate_x
	if self._show then self._show:SetRotateX(rotate_x) end
end
function CommonEntity:GetRotateX()
	return self._rotate_x
end

function CommonEntity:SetRotateY(rotate_y)
	self._rotate_y = rotate_y
	if self._show then self._show:SetRotateY(rotate_y) end
end
function CommonEntity:GetRotateY()
	return self._rotate_x
end

function CommonEntity:SetRotateZ(rotate_z)
	self._rotate_z = rotate_z
	if self._show then self._show:SetRotateZ(rotate_z) end
end
function CommonEntity:GetRotateZ()
	return self._rotate_z
end

function CommonEntity:SetRed(red)
	self._red = red
	if self._show then self._show:SetRed(red) end
end
function CommonEntity:GetRed()
	return self._red
end

function CommonEntity:SetGreen(green)
	self._green = green
	if self._show then self._show:SetGreen(green) end
end
function CommonEntity:GetGreen()
	return self._green
end

function CommonEntity:SetBlue(blue)
	self._blue = blue
	if self._show then self._show:SetBlue(blue) end
end
function CommonEntity:GetBlue()
	return self._blue
end

function CommonEntity:SetAlpha(alpha)
	self._alpha = alpha
	local abs_alpha = 1
	if self._parent then
		abs_alpha = self._parent._abs_alpha * alpha
	else
		abs_alpha = alpha
	end
	if self._show then
		self._show:SetAlpha(abs_alpha)
	end
end
function CommonEntity:GetAlpha()
	return self._alpha
end

function CommonEntity:SetVisible(visible)
	self._visible = visible
	local abs_visible = true
	if self._parent then
		abs_visible = self._parent._abs_visible and visible
	else
		abs_visible = visible
	end
	if self._show then
		self._show:SetVisible(abs_visible)
	end
end

function CommonEntity:SetDisable(disable)
	self._disable = disable
	if self._parent then
		self._abs_disable = self._parent._abs_disable or disable
	else
		self._abs_disable = disable
	end
end
